package com.bole.controller;


import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.brand.TbCarSeriesDto;
import com.bole.feign.CarSeriesFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("series")
@Api(value = "车系管理接口")
public class CarSeriesController {

    @Autowired
    private CarSeriesFeign carSeriesFeign;

    @RequestMapping("carSeriesList")
    public String carSeriesList(){
        return "/car/car_series_list";
    }

    @GetMapping("getSeriesInfo")
    @ApiOperation(value = "查询广告分类信息",notes = "查询广告分类信息")
    @ResponseBody
    public Result getSeriesInfo(){
        List<TbCarSeriesDto> carSeriesInfo = carSeriesFeign.getCarSeriesInfo();
        return Result.response(ResultEnum.OK).setData(carSeriesInfo);
    }


    @PostMapping("saveSeriesInfo")
    @ApiOperation(value = "增加广告分类信息",notes = "增加广告分类信息")
    @ApiImplicitParam(name = "carSeriesDto",value = "广告分类对象",required = true,dataTypeClass = TbCarSeriesDto.class)
    @ResponseBody
    public Result saveSeriesInfo(@RequestBody TbCarSeriesDto carSeriesDto){
        carSeriesFeign.saveCarSeriesInfo(carSeriesDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("toUpdate/{id}")
    @ApiOperation(value = "广告信息回显",notes = "没啥好注释的")
    @ApiImplicitParam(name = "id",value = "广告id",required = true,dataTypeClass = Long.class)
    @ResponseBody
    public Result toUpdate(@PathVariable("id")Long id){
        TbCarSeriesDto carSeriesDto = carSeriesFeign.toUpdate(id);
        return Result.response(ResultEnum.OK).setData(carSeriesDto);
    }


    @PostMapping("updateSeriesInfo")
    @ApiOperation(value = "修改信息",notes = "修改信息")
    @ApiImplicitParam(name = "carSeriesDto",value = "广告分类对象",required = true,dataTypeClass = TbCarSeriesDto.class)
    @ResponseBody
    public Result updateSeriesInfo(@RequestBody TbCarSeriesDto carSeriesDto){
        carSeriesFeign.updateContentCateInfo(carSeriesDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("deleteBatch/{ids}")
    @ApiOperation(value = "批量删除信息",notes = "批量删除信息")
    @ApiImplicitParam(name = "ids",value = "广告id集",required = true,paramType = "path",dataTypeClass = Long.class)
    @ResponseBody
    public Result deleteBatch(@PathVariable("ids")Long[] ids){
        List<Long> idss = new ArrayList<>();
        for (Long id : ids) {
            idss.add(id);
        }
        carSeriesFeign.deleteBatch(idss);
        return Result.response(ResultEnum.OK);
    }
}
